from selenium import webdriver
from selenium.webdriver.common.by import By
import os
import time

driver = webdriver.Chrome()
url = 'file:///' + os.path.abspath(('html') + '/注册实例.html')
driver.get(url)

# 定位账号,填写
time.sleep(2)
user = driver.find_element(By.ID, 'user')
user.send_keys('wuxn')

# 定位密码,填写
time.sleep(2)
password = driver.find_element(By.ID, 'password')
password.send_keys('123')

# 定位电话号码,填写
time.sleep(2)
tel = driver.find_element(By.ID, 'tel')
tel.send_keys('12345678912')

# 定位邮箱, 填写
time.sleep(2)
email = driver.find_element(By.ID, 'email')
email.send_keys('123@163.com')

# 定位注册用户的按钮,点击
time.sleep(2)
btn = driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()


# 切换到指定frame1
driver.switch_to.frame('idframe1')

# 定位账号,填写
time.sleep(2)
user = driver.find_element(By.ID, 'userA')
user.send_keys('wuxn')

# 定位密码,填写
time.sleep(2)
password = driver.find_element(By.ID, 'passwordA')
password.send_keys('123')

# 定位电话号码,填写
time.sleep(2)
tel = driver.find_element(By.ID, 'telA')
tel.send_keys('12345678912')

# 定位邮箱, 填写
time.sleep(2)
email = driver.find_element(By.ID, 'emailA')
email.send_keys('123@163.com')

# 定位注册用户的按钮,点击
time.sleep(2)
btnA = driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

# 切换到指定frame2
# 切换到父级frame
driver.switch_to.parent_frame()
driver.switch_to.frame('myframe2')
# 定位账号,填写
time.sleep(2)
user = driver.find_element(By.ID, 'userB')
user.send_keys('wuxn')

# 定位密码,填写
time.sleep(2)
password = driver.find_element(By.ID, 'passwordB')
password.send_keys('123')

# 定位电话号码,填写
time.sleep(2)
tel = driver.find_element(By.ID, 'telB')
tel.send_keys('12345678912')

# 定位邮箱, 填写
time.sleep(2)
email = driver.find_element(By.ID, 'emailB')
email.send_keys('123@163.com')

# 定位注册用户的按钮,点击
time.sleep(2)
btnB = driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()


driver.quit()